package fip.map.br;

import java.util.ArrayList;

public class WeatherData implements Subject{

	private ArrayList<Observer> observers; 
	private float temperature;
	private float humidity;
	private float pressure;
	
	public WeatherData(){
		this.observers=new ArrayList<Observer>();
	}
	public void removeObserver(Observer o){
		int i = observers.indexOf(o); 
		if(i>=0){
			observers.remove(i);
		}
	}
	public void notifyObservers(){
		for(int i = 0; i < observers.size(); i++){
			Observer observer = (Observer)observers.get(i);
			observer.update(temperature, humidity, pressure);
		}
	}
	public void measurmentsChanged(){
		notifyObservers();
	}
	public void registrerObserver(Observer o) {
		this.observers.add(o);
	}
	public void setMeasurments(float temperature, float humidity, float preassure){
		this.temperature = temperature;
		this.humidity = humidity; 
		this.pressure = preassure;
		measurmentsChanged();
	}
	public ArrayList<Observer> getObservers() {
		return observers;
	}
	public float getTemperature() {
		return temperature;
	}
	public float getHumidity() {
		return humidity;
	}
	public float getPressure() {
		return pressure;
	}
	
}
